package com.cwnu.config;

import com.google.common.base.Predicates;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @ProjectName: mall-cwnu
 * @Titile: SwaggerConfig
 * @Author: Lucky
 * @Description: Swagger的配置类
 */
@SpringBootConfiguration //配置标识，代表它是一个配置类
@EnableSwagger2 //让swagger生效
public class SwaggerConfig {
    // 接口大标题
    private final String title = "mall项目API";
    // 具体的描述
    private final String description = "mall项目API文档";
    // 接口版本号
    private final String version = "V1.0";
    // 服务说明url，服务条款
    private final String termsOfServiceUrl = "http://www.cwnu.edu.cn";
    // licence，许可证
    //private final String license = "MIT";
    // licnce url，许可网址
    //private final String licenseUrl = "https://mit-license.org/";
    // 接口作者联系方式
    private final Contact contact = new Contact("lucky", "http://www.cwnu.edu.cn", "2841958846@qq.com");

    @Bean //一个单例，一个实例，放在IOC容器中
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(info())
                .groupName("lucky.team")
                .select()
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build();
    }
    private ApiInfo info() {
        return new ApiInfoBuilder().title(title).termsOfServiceUrl(termsOfServiceUrl).description(description)
                .version(version).contact(contact).build();
    }
}
